<template>
    <div class="login-root">
        <div class="box-root flex-flex flex-direction--column" style="min-height: 100vh;flex-grow: 1;">
            <div class="loginbackground box-background--white padding-top--64">
                <div class="loginbackground-gridContainer">
                    <div class="box-root flex-flex" style="grid-area: top / start / 8 / end;">
                        <div class="box-root"
                            style="background-image: linear-gradient(white 0%, rgb(247, 250, 252) 33%); flex-grow: 1;">
                        </div>
                    </div>
                    <div class="box-root flex-flex" style="grid-area: 4 / 2 / auto / 5;">
                        <div class="box-root box-divider--light-all-2 animationLeftRight tans3s" style="flex-grow: 1;">
                        </div>
                    </div>
                    <div class="box-root flex-flex" style="grid-area: 6 / start / auto / 2;">
                        <div class="box-root box-background--blue800" style="flex-grow: 1;"></div>
                    </div>
                    <div class="box-root flex-flex" style="grid-area: 7 / start / auto / 4;">
                        <div class="box-root box-background--blue animationLeftRight" style="flex-grow: 1;"></div>
                    </div>
                    <div class="box-root flex-flex" style="grid-area: 8 / 4 / auto / 6;">
                        <div class="box-root box-background--gray100 animationLeftRight tans3s" style="flex-grow: 1;">
                        </div>
                    </div>
                    <div class="box-root flex-flex" style="grid-area: 2 / 15 / auto / end;">
                        <div class="box-root box-background--cyan200 animationRightLeft tans4s" style="flex-grow: 1;">
                        </div>
                    </div>
                    <div class="box-root flex-flex" style="grid-area: 3 / 14 / auto / end;">
                        <div class="box-root box-background--blue animationRightLeft" style="flex-grow: 1;"></div>
                    </div>
                    <div class="box-root flex-flex" style="grid-area: 4 / 17 / auto / 20;">
                        <div class="box-root box-background--gray100 animationRightLeft tans4s" style="flex-grow: 1;">
                        </div>
                    </div>
                    <div class="box-root flex-flex" style="grid-area: 5 / 14 / auto / 17;">
                        <div class="box-root box-divider--light-all-2 animationRightLeft tans3s" style="flex-grow: 1;">
                        </div>
                    </div>
                </div>
            </div>
            <div class="box-root padding-top--24 flex-flex flex-direction--column" style="flex-grow: 1; z-index: 9;">
                <div class="box-root padding-top--48 padding-bottom--24 flex-flex flex-justifyContent--center">
                    <h1 v-if="page === 'login'"><a href="http://blog.stackfindover.com/" rel="dofollow">管理员登录</a></h1>
                </div>
                <div class="formbg-outer">
                    <div class="formbg">
                        <div class="formbg-inner padding-horizontal--48">
                           

                            <form id="stripe-login" v-show="page === 'login'">
                                <div class="field padding-bottom--24">
                                    <label for="account">账号</label>
                                    <input id="account" name="account" pattern=".{5,18}" title="账号长度必须为5到18位" placeholder="输入账号"
                                        required>
                                </div>
                                <div class="field padding-bottom--24">
                                    <div class="grid--50-50">
                                        <label for="password">密码</label>
                                        <div class="reset-pass">
                                            <!-- <a href="#">忘记密码？</a> -->
                                        </div>
                                    </div>
                                    <input id="password" type="password" name="password" pattern=".{6,16}"
                                        title="密码长度必须为6到16位" placeholder="输入密码" required>
                                </div>
                                <div class="field field-checkbox padding-bottom--24 flex-flex align-center">
                                    <label for="checkbox">
                                        <input id="savePassword" type="checkbox"> 记住密码
                                    </label>
                                </div>
                                <div class="field padding-bottom--24">
                                    <input type="submit" name="submit" value="登录">
                                </div>
                                <div class="field">
                                
                                </div>
                            </form>



                        

                        </div>
                    </div>
                    <div class="footer-link padding-top--24">
                       
                        <div class="listing padding-top--24 padding-bottom--24 flex-flex center-center">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { registerAPI, loginAPI } from '@/apis/loginApi'
import { useUserStore } from "@/stores/user";
import { ElMain, ElMessage ,ElNotification} from 'element-plus';
import router from '@/router/index'
import CryptoJS from "crypto-js";
const userStore = useUserStore();
const page = ref('login')


//记住密码
const savaPassword = () => {
    var rememberPasswordCheckbox = document.getElementById("savePassword");
    if (rememberPasswordCheckbox.checked) {
        console.log("记住密码已勾选:"+document.getElementById("account").value);
        localStorage.setItem('account', document.getElementById("account").value)
        localStorage.setItem('password', CryptoJS.AES.encrypt(document.getElementById("password").value, 'mijiu').toString())
    } else {
        console.log("记住密码未勾选");
    }
}
//加载账密
const loadcp = () => {
    var account = localStorage.getItem("account") ? localStorage.getItem("account") : null;
    var password = localStorage.getItem("password") ? CryptoJS.AES.decrypt(localStorage.getItem("password"), 'mijiu').toString(CryptoJS.enc.Utf8) : null;
    document.getElementById("account").value = account
    document.getElementById("password").value = password
    document.getElementById("savePassword").checked = true

};

//用户登录
const login = async () => {

    document.getElementById("stripe-login").addEventListener("submit", async function (event) {
        event.preventDefault();
        var account = document.getElementById("account").value;
        var password = document.getElementById("password").value;
        const res = await userStore.getUserInfo({ account, password })
        if (res.code === 0) {
            // ElMessage({ type: 'success', message: '登录成功' })
            ElNotification({
                title: '登录成功！',
                message: '欢迎您登录系统！',
                type: 'success',
            })
            savaPassword()
            document.getElementById("account").value=''
            document.getElementById("password").value=''
            router.replace({ path: "/index" })
        }
        else{
            ElMessage({ type: 'error', message: res.message })
        }
        

    });
}

//用户注册
// const register = async () => {
//     document.getElementById("stripe-register").addEventListener("submit", async function (event) {
//         event.preventDefault();
//         var account = document.getElementById("account_r").value;
//         var password = document.getElementById("password_r").value;
//         var password2 = document.getElementById("password2").value;
//         //校验两次密码是否一致
//         if (password !== password2) {
//             ElMessage({ type: 'error', message: '两次密码输入不一致！' })
//             return
//         }
//         const res = await userStore.registerAndLogin({ account: account, password: password, password2: password2 })

//         if (res.code === 0) {
           
//             ElNotification({
//                 title: '登录成功！',
//                 message: '欢迎您登录该平台',
//                 type: 'success',
//             })
//             savaPassword()
//             document.getElementById("account_r").value=''
//             document.getElementById("password_r").value=''
//             document.getElementById("password2").value=''
//             router.replace({ path: "/index" })

//         }else{
//             ElMessage({ type: 'error', message: res.message })
//         }

//     })
// }



onMounted(() => {
    login()
    // register()
    loadcp()
})
</script>

<style lang="scss" scoped>
* {
    padding: 0;
    margin: 0;
    color: #1a1f36;
    box-sizing: border-box;
    word-wrap: break-word;
    font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Ubuntu, sans-serif;
}

h1 {
    letter-spacing: -1px;
}

a {
    color: #5469d4;
    text-decoration: unset;
}

.login-root {
    background-color: #212d63;
    display: flex;
    width: 100%;
    min-height: 100vh;
    overflow: hidden;
}

.loginbackground {
    min-height: 692px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: 0;
    z-index: 0;
    overflow: hidden;
}

.flex-flex {
    display: flex;
}

.align-center {
    align-items: center;
}

.center-center {
    align-items: center;
    justify-content: center;
}

.box-root {
    box-sizing: border-box;
}

.flex-direction--column {
    -ms-flex-direction: column;
    flex-direction: column;
}

.loginbackground-gridContainer {
    display: -ms-grid;
    display: grid;
    -ms-grid-columns: [start] 1fr [left-gutter] (86.6px)[16] [left-gutter] 1fr [end];
    grid-template-columns: [start] 1fr [left-gutter] repeat(16, 86.6px) [left-gutter] 1fr [end];
    -ms-grid-rows: [top] 1fr [top-gutter] (64px)[8] [bottom-gutter] 1fr [bottom];
    grid-template-rows: [top] 1fr [top-gutter] repeat(8, 64px) [bottom-gutter] 1fr [bottom];
    justify-content: center;
    margin: 0 -2%;
    transform: rotate(-12deg) skew(-12deg);
}

.box-divider--light-all-2 {
    box-shadow: inset 0 0 0 2px #e3e8ee;
}

.box-background--blue {
    background-color: #5469d4;
}

.box-background--white {
    background-color: #ffffff;
}

.box-background--blue800 {
    background-color: #212d63;
}

.box-background--gray100 {
    background-color: #e3e8ee;
}

.box-background--cyan200 {
    background-color: #7fd3ed;
}

.padding-top--64 {
    padding-top: 64px;
}

.padding-top--24 {
    padding-top: 24px;
}

.padding-top--48 {
    padding-top: 48px;
}

.padding-bottom--24 {
    padding-bottom: 24px;
}

.padding-horizontal--48 {
    padding: 48px;
}

.padding-bottom--15 {
    padding-bottom: 15px;
}


.flex-justifyContent--center {
    -ms-flex-pack: center;
    justify-content: center;
}

.formbg {
    margin: 0px auto;
    width: 100%;
    max-width: 448px;
    background: white;
    border-radius: 4px;
    box-shadow: rgba(60, 66, 87, 0.12) 0px 7px 14px 0px, rgba(0, 0, 0, 0.12) 0px 3px 6px 0px;
}

span {
    display: block;
    font-size: 20px;
    line-height: 28px;
    color: #1a1f36;
}

label {
    margin-bottom: 10px;
}

.reset-pass a,
label {
    font-size: 14px;
    font-weight: 600;
    display: block;
}

.reset-pass>a {
    text-align: right;
    margin-bottom: 10px;
}

.grid--50-50 {
    display: grid;
    grid-template-columns: 50% 50%;
    align-items: center;
}

.field input {
    font-size: 16px;
    line-height: 28px;
    padding: 8px 16px;
    width: 100%;
    min-height: 44px;
    border: unset;
    border-radius: 4px;
    outline-color: rgb(84 105 212 / 0.5);
    background-color: rgb(255, 255, 255);
    box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px,
        rgba(0, 0, 0, 0) 0px 0px 0px 0px,
        rgba(0, 0, 0, 0) 0px 0px 0px 0px,
        rgba(60, 66, 87, 0.16) 0px 0px 0px 1px,
        rgba(0, 0, 0, 0) 0px 0px 0px 0px,
        rgba(0, 0, 0, 0) 0px 0px 0px 0px,
        rgba(0, 0, 0, 0) 0px 0px 0px 0px;
}

input[type="submit"] {
    background-color: rgb(84, 105, 212);
    box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px,
        rgba(0, 0, 0, 0) 0px 0px 0px 0px,
        rgba(0, 0, 0, 0.12) 0px 1px 1px 0px,
        rgb(84, 105, 212) 0px 0px 0px 1px,
        rgba(0, 0, 0, 0) 0px 0px 0px 0px,
        rgba(0, 0, 0, 0) 0px 0px 0px 0px,
        rgba(60, 66, 87, 0.08) 0px 2px 5px 0px;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.field-checkbox input {
    width: 20px;
    height: 15px;
    margin-right: 5px;
    box-shadow: unset;
    min-height: unset;
}

.field-checkbox label {
    display: flex;
    align-items: center;
    margin: 0;
}

a.ssolink {
    display: block;
    text-align: center;
    font-weight: 600;
}

.footer-link span {
    font-size: 14px;
    text-align: center;
}

.listing a {
    color: #697386;
    font-weight: 600;
    margin: 0 10px;
}

.animationRightLeft {
    animation: animationRightLeft 2s ease-in-out infinite;
}

.animationLeftRight {
    animation: animationLeftRight 2s ease-in-out infinite;
}

.tans3s {
    animation: animationLeftRight 3s ease-in-out infinite;
}

.tans4s {
    animation: animationLeftRight 4s ease-in-out infinite;
}

@keyframes animationLeftRight {
    0% {
        transform: translateX(0px);
    }

    50% {
        transform: translateX(1000px);
    }

    100% {
        transform: translateX(0px);
    }
}

@keyframes animationRightLeft {
    0% {
        transform: translateX(0px);
    }

    50% {
        transform: translateX(-1000px);
    }

    100% {
        transform: translateX(0px);
    }
}
</style>